package com.hethongviet.vending.helper.db;

import java.util.ArrayList;
import java.util.List;

import com.hethongviet.vending.Utils;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class MySQLiteHelper extends SQLiteOpenHelper
{
	public static final String DATABASE_NAME = "vending_machine.db";
	public static final int DATABASE_VERSION = 1;

	private List<String> _tableName = new ArrayList<String>();
	private List<String> _sqlQueryColumn = new ArrayList<String>();

	public MySQLiteHelper(Context context, List<String> tableName,
			List<String> sqlQueryColumn)
	{
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
		_sqlQueryColumn = sqlQueryColumn;
		_tableName = tableName;
	}

	@Override
	public void onCreate(SQLiteDatabase database)
	{
		Utils.debug("Create table if not exists " + _tableName + "("
				+ _sqlQueryColumn + ")");
		// if(_tableName == null || _tableName.size() == 0) return;
		for (int i = 0; i < _tableName.size(); i++)
		{
			database.execSQL("CREATE TABLE IF NOT EXISTS " + _tableName.get(i)
					+ "(" + _sqlQueryColumn.get(i) + ")");
		}
	}

	public void createTable(String tableName, String sqlQueryColumn)
	{
		// TODO Auto-generated method stub

	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
	{
		Utils.debug("Upgrading database from version " + oldVersion + " to "
				+ newVersion + ", which will destroy all old data");
		db.execSQL("DROP TABLE IF EXISTS " + _tableName);
		onCreate(db);
	}
}
